import json

import pandas as pd

txtfile = open(r"D:\Chrome_download\Correted-ProgrammableWeb-dataset-main\data\raw\api_mashup\active_mashups_data.txt")
txtcontent = txtfile.read()
jsondata = json.loads(txtcontent)

# print(len(jsondata))

titleList = []
numList = []

api_usetime = {}

for api in jsondata:
    if api != None:
        titleList.append(api["title"])
        numList.append(len(api["related_apis"]))
        for relate_api in api["related_apis"]:
            if relate_api:
                if relate_api["url"] in api_usetime.keys():
                    api_usetime[relate_api["url"]] += 1
                else:
                    api_usetime[relate_api["url"]] = 1
        

column = ["title", "api_num"]
df = pd.DataFrame(zip(titleList, numList), columns=column)
df.to_csv("api_per_mashup.csv")
df = pd.DataFrame.from_dict(api_usetime, orient='index')
df.to_csv("api_usetime.csv")





